package com.example.demo.test.myThread;

import lombok.SneakyThrows;

public class ThreadTest3 implements Runnable {
    // private static final Integer TICKET=100;
    private static Integer tickets = 1000;
    private  Object lock = new Object();

    @SneakyThrows
    @Override
    public void run() {
        synchronized (lock) {
            while (tickets > 0) {
               synchronized (this){
                   sell();
               }

            }
        }
    }

    private synchronized void sell() throws InterruptedException {
        System.out.println(Thread.currentThread().getName() +
                "正在出售第" + tickets-- + "张票");
    }
}
